import 'package:enterprise_v6_app/app/components/special_operation/custom_title_chart_page.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/widget_extension.dart';
import 'package:enterprise_v6_app/app/modules/application/basic_information/equipment_facilities/equipment_facilities_controller.dart';
import 'package:enterprise_v6_app/router/app_pages.dart';

/// 设备设施页面
class EquipmentFacilitiesPage extends StatelessWidget {
  EquipmentFacilitiesPage({super.key});

  final controller = Get.put(EquipmentFacilitiesController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
        init: controller,
        builder: (_) {
          return Container(
            alignment: Alignment.topCenter,
            padding: EdgeInsets.symmetric(horizontal: 14.w, vertical: 12.w),
            child: SingleChildScrollView(
              child: Column(
                children: [
                  CustomTitleChartPage(
                    title: '设备设施',
                    child: Column(children: [
                      _getContentView(
                        icon: AppImages.icon_gear,
                        title: '在用',
                        num: controller.statisticsEntity.isUsed!,
                      ),
                      AppGaps.vGap16,
                      _getContentView(
                        icon: AppImages.icon_gear,
                        title: '停用',
                        num: controller.statisticsEntity.unUsed!,
                        iconColor: const Color(0xffFD6B6B),
                        numColor: const Color(0xffFD6B6B),
                      ),
                    ]),
                  ).clickOnce(() {
                    Get.toNamed(AppRoutes.equipmentList);
                  }),
                  AppGaps.vGap16,
                  CustomTitleChartPage(
                    title: '部件/副件',
                    child: Column(children: [
                      _getContentView(
                        icon: AppImages.icon_un_delete,
                        title: '正常',
                        num: controller.statisticsEntity.normal!,
                      ),
                      AppGaps.vGap16,
                      _getContentView(
                        icon: AppImages.icon_replaced,
                        title: '待更换',
                        num: controller.statisticsEntity.change!,
                      ),
                      AppGaps.vGap16,
                      _getContentView(
                        icon: AppImages.icon_verified,
                        title: '待校验',
                        num: controller.statisticsEntity.check!,
                      ),
                      AppGaps.vGap16,
                      _getContentView(
                        icon: AppImages.icon_trash_can,
                        title: '待检定',
                        num: controller.statisticsEntity.scrap!,
                      ),
                    ]),
                  ).clickOnce(() {
                    Get.toNamed(AppRoutes.partsAccessoryList);
                  }),
                  AppGaps.vGap16,
                  _getTitleView(
                    title: '设备检验检测台账',
                    onTap: () {
                      Get.toNamed(AppRoutes.equipmentInspectionTestingLedgerPage);
                    },
                  ),
                  AppGaps.vGap16,
                  _getTitleView(
                    title: '部件管理台账',
                    onTap: () {
                      Get.toNamed(AppRoutes.componentManagementLedgerPage);
                    },
                  ),
                  AppGaps.vGap16,
                  _getTitleView(
                    title: '联锁清单',
                    onTap: () {
                      Get.toNamed(AppRoutes.interlockList);
                    },
                  ),
                  AppGaps.vGap16,
                  _getTitleView(
                    title: '联锁摘除清单台账',
                    onTap: () {
                      Get.toNamed(AppRoutes.chainRemovalListPage);
                    },
                  ),
                ],
              ),
            ),
          );
        });
  }

  /// 获取标题显示
  Widget _getTitleView({required VoidCallback onTap, String? title}) {
    return Container(
        alignment: Alignment.center,
        padding: EdgeInsets.symmetric(vertical: 12.w),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(8.w),
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            SvgPicture.asset(AppImages.icon_chain),
            AppGaps.hGap8,
            Text(
              title ?? '',
              style: TextStyle(
                fontSize: 15.sp,
                fontWeight: FontWeight.w500,
                color: const Color(0xff333333),
              ),
            )
          ],
        )).clickOnce(onTap);
  }

  /// 获取统计内容显示
  Widget _getContentView({
    required String icon,
    required String title,
    required int num,
    Color? iconColor,
    Color? numColor,
  }) {
    return Row(
      children: [
        SvgPicture.asset(
          icon,
          colorFilter: iconColor == null ? null : ColorFilter.mode(iconColor, BlendMode.srcIn),
        ),
        AppGaps.hGap6,
        Text(
          title,
          style: TextStyle(
            fontSize: 14.sp,
            height: 1.2,
            fontWeight: FontWeight.w400,
            color: const Color(0xffA5A6B5),
          ),
        ),
        AppGaps.hGap30,
        Expanded(
          child: Container(
            alignment: Alignment.center,
            height: 2.w,
            decoration: const BoxDecoration(
              gradient: LinearGradient(
                begin: Alignment.centerLeft,
                end: Alignment.centerRight,
                colors: [
                  Color(0xFFffffff),
                  Color(0xFF5C6DFF),
                ],
              ),
            ),
          ),
        ),
        AppGaps.hGap10,
        Text(
          num.toString(),
          style: TextStyle(
            fontSize: 14.sp,
            height: 1.2,
            fontWeight: FontWeight.w500,
            color: numColor ?? const Color(0xff5C6DFF),
          ),
        ),
      ],
    );
  }
}
